package com.yunhe.common.mybatis.domain;

/**
 * @ClassName PageResult
 * @Description TODO
 * @Author HeTao
 * @Date 2020/10/15 17:37
 * @Version 1.0
 **/

import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * 分页结果
 */
public class PageResult {

    /**
     * 当前页
     */
    @ApiModelProperty(value = "当前页")
    private int pageIndex;
    /**
     * 当前页多少数据
     */
    @ApiModelProperty(value = "当前页多少数据")
    private int pageSize;
    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private int total;
    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数")
    private int totalPage;
    /**
     * 记录
     */
    @ApiModelProperty(value = "数据")
    private List records;

    public PageResult() {
    }

    public PageResult(int pageIndex, int pageSize, int total, List records) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.total = total;
        this.records = records;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List getRecords() {
        return records;
    }

    public void setRecords(List records) {
        this.records = records;
    }

    public int getTotalPage() {
        if(total == 0 || pageSize==0){
            return 0;
        }
        int countPage = total / pageSize;
        int remainder = total % pageSize;
        if(countPage ==0){
            countPage = countPage + 1;
        }else {
            if(remainder != 0){
                countPage = countPage + 1;
            }
        }
        return countPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
}